import { View } from "../../../mvc/core/View";
import { IUpdateMagicWeaponInfo } from "./IUpdateMagicWeaponInfo";
import { ObjCreate } from "../common/ObjCreate";
import { MagicWeaponItemData } from "./MagicWeaponItemData";
import { MagicWeaponItemRenderer } from "./renderer/MagicWeaponItemRenderer";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { ListEvent } from "../../../../fl/events/ListEvent";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { ImagesConst } from "../../resource/ImagesConst";
import { EBind } from "../../../../Message/Public/EBind";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { AutoGuideClickChildNames } from "../common/guide/AutoGuideClickChildNames";
type int = number;
//class MagicWeaponBase
    
    export  class MagicWeaponBase extends View implements IUpdateMagicWeaponInfo
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc2=null;
            var loc5=null;
            var loc1=ObjCreate.createBg(19, 60, 400, 427, this);
            loc2 = new Object /* flash.display.Sprite */();
            loc2.mouseChildren = false;
            loc2.mouseEnabled = false;
            ObjCreate.setObjAttri(loc2, 24, 65, -1, -1, this);
            var loc3=new MagicWeaponItemData();
            var loc4=0;
            while (loc4 < 6) 
            {
                (loc5 = new MagicWeaponItemRenderer()).data = loc3;
                loc5.x = loc4 % 3 * 131;
                loc5.y = loc4 < 3 ? 0 : 42;
                loc2.addChild(loc5);
                ++loc4;
            }
            this._materialList = ObjCreate.createTileList(24, 65, 395, 84, this);
            this._materialList.scrollPolicy = ScrollPolicy.OFF;
            this._materialList.columnWidth = 131;
            this._materialList.rowHeight = 42;
            this._materialList.setStyle("cellRenderer", MagicWeaponItemRenderer);
            this._materialList.addEventListener(ListEvent.ITEM_CLICK, this.onSelectItemHandler);
            this._materiaPageSelecter = ObjCreate.createPageSelecter(157, 150, this);
            this._materiaPageSelecter.mode = PageSelecter.CompleteMode;
            this._materiaPageSelecter.addEventListener(flash.events.Event.CHANGE, this.onEquipmentPageChange);
            ObjCreate.createBg(31, 171, 380, 2, this, ImagesConst.SplitLine);
            return;
        }

        protected set operateMaterialData(arg1: Array<any>)
        {
            var loc3=0;
            var loc4=null;
            this._needMaterialNum = 0;
            var loc1=[];
            var loc2=arg1.length;
            loc3 = 0;
            while (loc3 < 10) 
            {
                if (loc3 < loc2) 
                {
                    loc1[loc3] = this._materialData[loc3];
                    if (loc4 = this._materialData[loc3]) 
                    {
                        loc4.isSelect = true;
                        if (this._panelType != MagicWeaponBase.IDENTIFY_PANEL) 
                        {
                            if (this._panelType == MagicWeaponBase.RESOLVE_PANEL) 
                            {
                                if (loc4.itemData.itemExInfo.bind != EBind._EBindYes) 
                                {
                                    loc6 = ((loc5 = this)._noBindStoneNum + 1);
                                    loc5._noBindStoneNum = loc6;
                                }
                                else 
                                {
                                    loc6 = ((loc5 = this)._bindStoneNum + 1);
                                    loc5._bindStoneNum = loc6;
                                }
                            }
                        }
                        else 
                        {
                            var loc5;
                            var loc6=((loc5 = this)._needMaterialNum + 1);
                            loc5._needMaterialNum = loc6;
                        }
                    }
                }
                else 
                {
                    loc1[loc3] = new MagicWeaponItemData(null);
                }
                ++loc3;
            }
            if (this._operateMaterialList) 
            {
                this._operateMaterialList.dataProvider = new DataProvider(loc1);
                this._operateMaterialList.drawNow();
            }
            return;
        }

        protected onSelectItemHandler(arg1: ListEvent): void
        {
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc1=arg1.item as MagicWeaponItemData;
            if (loc1) 
            {
                loc2 = 0;
                while (loc2 < 10) 
                {
                    if ((loc3 = this._operateMaterialList.dataProvider.getItemAt(loc2) as MagicWeaponItemData) && loc3.itemData == null) 
                    {
                        this._operateMaterialList.dataProvider.replaceItemAt(loc1, loc2);
                        var loc5=0;
                        var loc6=this._materialData;
                        for(loc4 of loc6) 
                        {
                            if (loc4.itemData.uid != loc1.itemData.uid) 
                            {
                                continue;
                            }
                            loc4.isSelect = true;
                            if (this._panelType != MagicWeaponBase.IDENTIFY_PANEL) 
                            {
                                if (this._panelType == MagicWeaponBase.RESOLVE_PANEL) 
                                {
                                    if (ItemsUtil.isBind(loc4.itemData)) 
                                    {
                                        loc8 = ((loc7 = this)._bindStoneNum + 1);
                                        loc7._bindStoneNum = loc8;
                                    }
                                    else 
                                    {
                                        loc8 = ((loc7 = this)._noBindStoneNum + 1);
                                        loc7._noBindStoneNum = loc8;
                                    }
                                }
                            }
                            else 
                            {
                                var loc7;
                                var loc8=((loc7 = this)._needMaterialNum + 1);
                                loc7._needMaterialNum = loc8;
                            }
                            break;
                        }
                        break;
                    }
                    ++loc2;
                }
                this._operateMaterialList.drawNow();
            }
            return;
        }

        protected restPage(): void
        {
            if (this._materiaPageSelecter) 
            {
                this._materiaPageSelecter.updatePageTxt(1);
                this._materiaPageSelecter.currentPage = 1;
            }
            return;
        }

        protected currentPage(): void
        {
            var loc1=0;
            if (this._materiaPageSelecter) 
            {
                loc1 = this.pageSelecter.currentPage;
                this._materiaPageSelecter.currentPage = 1;
                this._materiaPageSelecter.updatePageTxt(loc1);
            }
            return;
        }

        public get pageSelecter(): PageSelecter
        {
            if (this._materiaPageSelecter) 
            {
                return this._materiaPageSelecter;
            }
            return null;
        }

        public updateWeaponInfo(): void
        {
            return;
        }

        protected set operateMaterialList(arg1: GTileList)
        {
            this._operateMaterialList = arg1;
            return;
        }

        protected onEquipmentPageChange(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._materiaPageSelecter.currentPage;
            var loc2=(loc1 - 1) * 6;
            var loc3=this._materialData.length - loc2 > 6 ? 6 : this._materialData.length - loc2;
            var loc4=[];
            var loc5=loc2;
            while (loc5 < loc2 + loc3) 
            {
                loc4[loc5 - loc2] = this._materialData[loc5];
                if (loc5 - loc2 != 0) 
                {
                    MagicWeaponItemData(loc4[loc5 - loc2]).name = "";
                }
                else 
                {
                    MagicWeaponItemData(loc4[0]).name = AutoGuideClickChildNames.MagicWeapon_Identify1;
                }
                ++loc5;
            }
            this._materialList.dataProvider = new DataProvider(loc4);
            this._materialList.drawNow();
            return;
        }

        public set panelType(arg1: string)
        {
            this._panelType = arg1;
            return;
        }

        public static /* const */IDENTIFY_PANEL: string="identifyPanel";

        public static /* const */RESOLVE_PANEL: string="resolvePanel";

        protected /* var */_materialList: GTileList;

        protected /* var */_materialData: Array<any>;

        protected /* var */_needMaterialNum: int;

        protected /* var */_noBindStoneNum: int;

        protected /* var */_bindStoneNum: int;

        protected /* var */_materiaPageSelecter: PageSelecter;

        /* internal */ /* var */_operateMaterialList: GTileList;

        /* internal */ /* var */_panelType: string;
    }
